<template>
  <div class="main-con">
    <div>
      <span>自动审核</span>
      <el-switch v-model="enable" size="large" style="margin: 0 10px 0 20px" @change="setControl" />
      <span>{{ enable ? '开启' : '关闭' }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, onBeforeMount } from 'vue'
  import { ContentService } from '@/api/contentApi'

  const enable = ref(false)

  const setControl = async () => {
    try {
      const response = await ContentService.controlConfig({ enable: enable.value })
      // 处理后端返回的统一数据结构 { code: "200", data: {}, errorData: {}, message: "成功", ... }
      if (response.code !== '200') {
        console.error('设置风控配置失败:', response.message || '未知错误')
      }
    } catch (error) {
      console.error('设置风控配置失败:', error)
    }
  }

  const controlInfo = async () => {
    try {
      const response = await ContentService.getControl()
      // 处理后端返回的统一数据结构 { code: "200", data: {}, errorData: {}, message: "成功", ... }
      if (response.code === '200' && response.data !== undefined) {
        enable.value = response.data
      } else {
        console.error('获取风控配置失败:', response.message || '未知错误')
      }
    } catch (error) {
      console.error('获取风控配置失败:', error)
    }
  }

  onBeforeMount(() => {
    controlInfo()
  })
</script>

<style lang="scss" scoped>
  .main-con {
    padding: 20px;
    background: var(--art-bg-color);
  }
</style>
